
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>结合Python读取Excel · MLSQL Engine 文档</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-lightbox/css/lightbox.min.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../styles/image.css">
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="write_excel.html" />
    
    
    <link rel="prev" href="pyjava.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    MLSQL Engine产品简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../howtouse/">
            
                <a href="../howtouse/">
            
                    
                    MLSQL Engine基本安装
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../howtouse/configuration.html">
            
                <a href="../howtouse/configuration.html">
            
                    
                    启动参数详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../howtouse/deploy.html">
            
                <a href="../howtouse/deploy.html">
            
                    
                    Local
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../howtouse/k8s_deploy.html">
            
                <a href="../howtouse/k8s_deploy.html">
            
                    
                    K8s部署
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../howtouse/yarn_deploy.html">
            
                <a href="../howtouse/yarn_deploy.html">
            
                    
                    Yarn部署
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../security/README.md">
            
                <span>
            
                    
                    MLSQL Engine安全加固
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../security/token_control.html">
            
                <a href="../security/token_control.html">
            
                    
                    接口访问Token设置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../security/custom_control.html">
            
                <a href="../security/custom_control.html">
            
                    
                    自定义接口访问策略
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../auth/">
            
                <a href="../auth/">
            
                    
                    MLSQL Engine数据访问控制
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" >
            
                <span>
            
                    
                    解析时表权限
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" >
            
                <span>
            
                    
                    运行时表权限表以及列权限
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" >
            
                <span>
            
                    
                    客户端开发
            
                </span>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" >
            
                <span>
            
                    
                    服务端开发
            
                </span>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../api/README.md">
            
                <span>
            
                    
                    MLSQL Engine Rest接口详解
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../api/run-script.html">
            
                <a href="../api/run-script.html">
            
                    
                    /run/script
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="./">
            
                <a href="./">
            
                    
                    MLSQL Python支持
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="env.html">
            
                <a href="env.html">
            
                    
                    环境依赖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="etl.html">
            
                <a href="etl.html">
            
                    
                    数据处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="train.html">
            
                <a href="train.html">
            
                    
                    模型训练
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="pyjava.html">
            
                <a href="pyjava.html">
            
                    
                    PyJava API简介
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.6.5" data-path="read_excel.html">
            
                <a href="read_excel.html">
            
                    
                    结合Python读取Excel
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="write_excel.html">
            
                <a href="write_excel.html">
            
                    
                    结合Python保存Excel
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="resource.html">
            
                <a href="resource.html">
            
                    
                    K8s下的Python资源限制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" data-path="datamode.html">
            
                <a href="datamode.html">
            
                    
                    dataMode 详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" data-path="py_paralell.html">
            
                <a href="py_paralell.html">
            
                    
                    Python并行度你所需要知道的
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../plugin/">
            
                <a href="../plugin/">
            
                    
                    插件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../plugin/online_install.html">
            
                <a href="../plugin/online_install.html">
            
                    
                    网络安装插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../plugin/offline_install.html">
            
                <a href="../plugin/offline_install.html">
            
                    
                    离线安装插件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >结合Python读取Excel</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x7ED3;&#x5408;python&#x8BFB;&#x53D6;excel">&#x7ED3;&#x5408;Python&#x8BFB;&#x53D6;Excel</h1>
<p>MLSQL 2.0.1-SNAPSHOT/2.0.1 &#x4EE5;&#x53CA;&#x4EE5;&#x4E0A;&#x7248;&#x672C;&#x53EF;&#x7528;</p>
<blockquote>
<p>MLSQL &#x63D0;&#x4F9B;&#x4E86; <a href="https://github.com/allwefantasy/mlsql-plugins/tree/master/mlsql-excel" target="_blank">excel&#x63D2;&#x4EF6;</a>&#xFF0C;&#x53EF;&#x4EE5;&#x8BA9;&#x7528;&#x6237;&#x8BFB;&#x5199;Excel&#x3002;&#x66F4;&#x591A;&#x8BE6;&#x60C5;&#x53C2;&#x8003;<a href="http://docs.mlsql.tech/mlsql-engine/plugin/" target="_blank">&#x63D2;&#x4EF6;</a></p>
</blockquote>
<p>Python&#x5BF9;Excel&#x7684;&#x652F;&#x6301;&#x4E5F;&#x5F88;&#x4E0D;&#x9519;&#xFF0C;&#x800C;MLSQL&#x652F;&#x6301;Python,&#x6240;&#x4EE5;&#x81EA;&#x7136;&#x80FD;&#x591F;&#x5728;MLSQL&#x64CD;&#x4F5C;&#x548C;&#x4F7F;&#x7528;Excel&#x6570;&#x636E;&#x3002;&#x8FD9;&#x6837;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;MLSQL&#x5C06;&#x5927;&#x89C4;&#x6A21;&#x7684;&#x6570;&#x636E;&#x53D8;&#x5C0F;&#xFF0C;&#x7136;&#x540E;&#x4FDD;&#x5B58;&#x6210;Excel&#x540E;&#x7528;&#x6237;&#x4E0B;&#x8F7D;&#x4E0B;&#x6765;&#x505A;&#x8FDB;&#x4E00;&#x6B65;&#x5904;&#x7406;&#x3002;</p>
<h2 id="&#x8BFB;&#x53D6;excel&#x6587;&#x4EF6;">&#x8BFB;&#x53D6;excel&#x6587;&#x4EF6;</h2>
<pre><code class="lang-shel">load binaryFile.`/tmp/wow.xlsx` as excel_table;
</code></pre>
<p>&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x8BFB;&#x53D6;&#x4E00;&#x4E2A;&#x76EE;&#x5F55;&#x4E0B;&#x6240;&#x6709;&#x7684;excel&#x6587;&#x4EF6;&#xFF0C;&#x53EA;&#x8981;&#x628A;&#x8DEF;&#x5F84;&#x5199;&#x5230;&#x76EE;&#x5F55;&#x5373;&#x53EF;&#x3002;</p>
<h2 id="ray&#x914D;&#x7F6E;">Ray&#x914D;&#x7F6E;</h2>
<pre><code>-- python&#x5904;&#x7406;&#x5B8C;&#x540E;&#x7684;&#x6570;&#x636E;&#x7684;schema
!python conf &quot;schema=st(field(file,binary))&quot;;
-- Python&#x8DD1;&#x5728;driver&#x7AEF;&#xFF0C;
!python conf &quot;runIn=driver&quot;;
-- &#x4E0D;&#x9700;&#x8981;&#x4ECE;Ray&#x96C6;&#x7FA4;&#x83B7;&#x53D6;&#x6570;&#x636E;&#xFF0C;&#x9700;&#x8981;&#x5C06;dataMode&#x8BBE;&#x7F6E;&#x4E3A;model.
!python conf &quot;dataMode=model&quot;;
</code></pre><h2 id="&#x4F7F;&#x7528;python&#x89E3;&#x6790;excel">&#x4F7F;&#x7528;Python&#x89E3;&#x6790;Excel</h2>
<pre><code class="lang-python">!ray on excel_table <span class="hljs-string">&apos;&apos;&apos;

import io
import ray
from pyjava.api.mlsql import RayContext
import pandas as pd
ray_context = RayContext.connect(globals(),None)

excel_file_binary_list = [item for item in RayContext.collect_from(ray_context.data_servers())]

df = pd.read_excel(io.BytesIO(excel_file_binary_list[0][&quot;content&quot;]))

context.build_result([row for row in df.to_dict(&apos;records&apos;)])

&apos;&apos;&apos;</span> named excel_data;
</code></pre>
<p>&#x7B80;&#x5355;&#x89E3;&#x91CA;&#x4E0B;&#x3002;</p>
<pre><code class="lang-python">ray_context = RayContext.connect(globals(),<span class="hljs-keyword">None</span>)
</code></pre>
<p>&#x83B7;&#x53D6;ray_context,&#x7B2C;&#x4E8C;&#x4E2A;&#x53C2;&#x6570;&#x4E3A;None&#x8868;&#x793A;&#x4E0D;&#x9002;&#x7528;Ray&#x96C6;&#x7FA4;&#x3002;</p>
<pre><code class="lang-python">excel_file_binary_list = [item <span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> RayContext.collect_from(ray_context.data_servers())]
</code></pre>
<p>&#x83B7;&#x53D6;&#x6240;&#x6709;&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#x3002;</p>
<pre><code class="lang-python">df = pd.read_excel(io.BytesIO(excel_file_binary_list[<span class="hljs-number">0</span>][<span class="hljs-string">&quot;content&quot;</span>]))
</code></pre>
<p>&#x6211;&#x4EEC;&#x8FD9;&#x91CC;&#x53EA;&#x6709;&#x4E00;&#x6761;&#x8BB0;&#x5F55;&#xFF0C;&#x5BF9;&#x5E94;&#x7684;&#x4E8C;&#x8FDB;&#x5236;&#x5185;&#x5BB9;&#x5B57;&#x6BB5;&#x662F;content.</p>
<pre><code class="lang-python">context.build_result([row <span class="hljs-keyword">for</span> row <span class="hljs-keyword">in</span> df.to_dict(<span class="hljs-string">&apos;records&apos;</span>)])
</code></pre>
<p>&#x5C06;&#x7ED3;&#x679C;&#x5C55;&#x5F00;&#x6210;&#x884C;&#x6784;&#x5EFA;&#x8FD4;&#x56DE;&#x3002;</p>
<p></p><div class="image-wrapper python-read_excel"><a href="http://docs.mlsql.tech/upload_images/490df52e-47f6-4dbf-8c8d-534a1dd679f9.png" data-lightbox="ecdaa0c2-6cf8-4d2d-b95a-3c97f2370ba5" data-title="" target="_blank"><img src="http://docs.mlsql.tech/upload_images/490df52e-47f6-4dbf-8c8d-534a1dd679f9.png" alt=""></a></div><p></p>
<h2 id="&#x9644;&#x5F55;">&#x9644;&#x5F55;</h2>
<p>&#x4E0B;&#x9762;&#x662F;&#x5B8C;&#x6574;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-python">load binaryFile.`/tmp/wow.xlsx` <span class="hljs-keyword">as</span> excel_table;
!pyInclude excel.read.py named read_excel;

-- ray &#x914D;&#x7F6E;
!python env <span class="hljs-string">&quot;PYTHON_ENV=source activate dev&quot;</span>;
!python conf <span class="hljs-string">&quot;schema=st(field(a,string),field(b,string))&quot;</span>;
!python conf <span class="hljs-string">&quot;runIn=driver&quot;</span>;
!python conf <span class="hljs-string">&quot;dataMode=model&quot;</span>;

!ray on excel_table <span class="hljs-string">&apos;&apos;&apos;

import io
import ray
from pyjava.api.mlsql import RayContext
import pandas as pd


ray_context = RayContext.connect(globals(),None)

excel_file_binary_list = [item for item in RayContext.collect_from(ray_context.data_servers())]

df = pd.read_excel(io.BytesIO(excel_file_binary_list[0][&quot;content&quot;]))

context.build_result([row for row in df.to_dict(&apos;records&apos;)])

&apos;&apos;&apos;</span> named excel_data;
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="pyjava.html" class="navigation navigation-prev " aria-label="Previous page: PyJava API简介">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="write_excel.html" class="navigation navigation-next " aria-label="Next page: 结合Python保存Excel">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"结合Python读取Excel","level":"1.6.5","depth":2,"next":{"title":"结合Python保存Excel","level":"1.6.6","depth":2,"path":"python/write_excel.md","ref":"python/write_excel.md","articles":[]},"previous":{"title":"PyJava API简介","level":"1.6.4","depth":2,"path":"python/pyjava.md","ref":"python/pyjava.md","articles":[]},"dir":"ltr"},"config":{"plugins":["image-class","lightbox"],"styles":{"website":"styles/image.css"},"pluginsConfig":{"image-class":{},"lightbox":{"jquery":true,"sameUuid":false},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"MLSQL Engine 文档","gitbook":"*","description":"MLSQL Engine 官方文档"},"file":{"path":"python/read_excel.md","mtime":"2020-08-31T10:51:02.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-09-03T03:59:44.434Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-lightbox/js/lightbox.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

